<?php

/**
 * The Image class. This class describes an image in the system. The image
 * can be seen as the canvas on which several filters are done to create
 * the final image.
 *
 * @version $Revision v1.00$
 * @author Bryan Spirit & Mark Kazemier
 */
abstract class Image
{
    private $m_hImage;
    
    /**
     * Constructs a new Image of width $iWidth and height $iHeight
     *
     * @throws ImageCreateException When image could not be created
     * @param integer The width of the image
     * @param integer The height of the image
     */
    public function __construct($iWidth, $iHeight)
    {
        $this->m_hImage = imagecreatetruecolor($iWidth, $iHeight);
        
        if(!$this->m_hImage)
            throw new ImageCreateException('The image could not be created');
    }
    
    /**
     * Destructs the image when object is destroyed
     */
    public function __destruct()
    {
        imagedestroy($this->m_hImage);
    }
    
    /**
     * Method to get the image resource
     *
     * @return The image resource
     */
    public function getResource()
    {
        return $this->m_hImage;
    }
    
    /**
     * Method to create the final image. Returns the output of the image
     *
     * @throws ImageCreateException When the image could not be created
     * @param integer The quality of the image, 100 is highest, 0 is lowest
     * @return string The output of the Image
     */
    public abstract function create($iQuality = 100);
    
    
    /**
     * Method to send the necessary headers to show the image
     */
    public abstract function header();
}
